/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import Beans.UserBean;
import Processes.Navigate;
import java.io.Serializable;
import javax.ejb.EJB;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import radio.sessions.AccountDetailsFacade;
import radio.sessions.AccountsFacade;

/**
 *
 * @author Kim
 */
public class User implements Serializable {

    @EJB
    private AccountsFacade accountsFacade;
    @EJB
    private AccountDetailsFacade accountDetailsFacade;
    private UserBean user = new UserBean();
    private String confirm, newPwd, oldPwd;

    public String getConfirm() {
        return confirm;
    }

    public void setConfirm(String confirm) {
        this.confirm = confirm;
    }

    public String getNewPwd() {
        return newPwd;
    }

    public void setNewPwd(String newPwd) {
        this.newPwd = newPwd;
    }

    public String getOldPwd() {
        return oldPwd;
    }

    public void setOldPwd(String oldPwd) {
        this.oldPwd = oldPwd;
    }

    public UserBean getUser() {
        return user;
    }

    public void setUser(UserBean user) {
        this.user = user;
    }

    /** Creates a new instance of User */
    public User() {
    }

    public User(UserBean user) {
        this.user = user;
    }

    public void edit() {
        if (confirm.equals(newPwd)) {
//            System.out.println(confirmnew + "  "+ newpwd); 
            FacesContext cxt = FacesContext.getCurrentInstance();
            cxt.addMessage("EditForm:confirm", new FacesMessage("Confirm Password does not match"));
        } else {
            System.out.println(this.user.getAccId());
//            Accounts acc=accountsFacade.findbyId(this.user.getAccId());
//            AccountDetails detail=acc.getAccountDetails();
//            detail.setAddress(this.user.getAddress());
//            accountDetailsFacade.edit(detail);
//            accountsFacade.edit(null);
            Navigate nav = (Navigate) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("navigate");
            nav.setUserpage("./ViewAccount.xhtml");
        }
    }
}
